<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<link href="/css/common.css" rel="stylesheet" type="text/css" />
<style>
input {width:150px;}
.wrapContent {margin:0 auto;padding:0 30px;}
.center {text-align:center;}
.block {padding:10px 30px;}
.line {border:none;border-bottom:1px solid #666;clear:both;}
.lineHeight{height:34px;line-height:34px;}
.right {text-align:right;width:120px;vertical-align:top}
.errMsg {color:red;margin:0 0 0 5px;}
</style>
</head>
<body>
<div class="wrapContent">
	<div class="block">
		<h2 class="center">添加快递公司</h2>
		<table style="width:500px;border:none;margin:50px auto 0;" cellpadding="0" cellspacing="0">
			<tr class="lineHeight">
				<td class="right">公司名称：</td>
				<td><input id="name"/><b id="nameErrMsg" class="errMsg">*</b></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">联系电话：</td>
				<td><input id="tel"/><b id="telErrMsg" class="errMsg">*</b></td>
			</tr>
			<tr class="lineHeight">
				<td class="right">备注：</td>
				<td><textarea id="remark" cols="40" rows="5"></textarea><b id="remarkErrMsg" class="errMsg"></b></td>
			</tr>
		</table>
	</div>
	<div class="center">
		<input id="submit" type="button" class="submitBtn" value="确定"/>
		<input id="back" type="button" class="submitBtn" value="返回"/>
	</div>
</div>
</body>
<script src="/js/lib.min.js" type="text/javascript"></script>
<script src="/js/md5.min.js" type="text/javascript"></script>
<script type="text/javascript">
var nameInput = $('#name'),
	nameErrMsg = $('#nameErrMsg'),
	telInput = $('#tel'),
	telErrMsg = $('#telErrMsg'),
	remarkInput = $('#remark'),
	remarkErrMsg = $('#remarkErrMsg'),
	backBtn = $('#back'),
	submitBtn = $('#submit');

backBtn.attr({onclick:function(){
	location.href='/admin/express.php?op=manage';
}});
submitBtn.attr({onclick:function(){
	var cName = $.trim(nameInput.val()),
		tel = $.trim(telInput.val()),
		remark = $.trim(remarkInput.val()),
		checkFlag = true;
	if (!cName) {
		nameErrMsg.html('请填写公司名称');
		!checkFlag && nameInput[0].focus();
		checkFlag = false;
	}else {
		nameErrMsg.html('*');
	}
	
	if (!tel || (!/^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$/.test(tel) && !/\d{10,11}/.test(tel))) {
		telErrMsg.html('请正确填写联系电话');
		!checkFlag && nameInput[0].focus();
		checkFlag = false;
	}else {
		telErrMsg.html('*');
	}
	
	if (!checkFlag) {
		return ;
	}
	
	submitBtn.val('正在处理，请稍后...');
	submitBtn[0].disabled = true;
	
	$.ajax({
		url:'/admin/express.php?op=doAdd',
		data:{'cname':cName, 'tel':tel, 'remark':remark},
		type:'POST',
		callback:function(res){
			submitBtn.val('确定');
			submitBtn[0].disabled = false;
			if (res.errno == '0'){
				alert('添加成功！');
				nameInput.val('');
				nameErrMsg.html('*');
				telInput.val('');
				telErrMsg.html('*');
				remarkInput.val('');
				remarkErrMsg.html('');
			}else{
				alert(res.errmsg);
			}
		}
	});
}});
</script>
</html>